package com.miyu.common.utils.taskJob;

import com.alibaba.fastjson.JSONObject;
import com.miyu.common.utils.commonUtils.RedisCache;
import com.miyu.common.utils.web.PropertiesUtil;
import java.util.concurrent.Callable;

/**
 * 多线程操作redis缓存
 * 不影响正常流程进行
 * index 指使用db
 * type 数据使用类型
 * 默认0 覆盖   1 插入在最前 2 在后插入
 */
public class RedisTaskCahe implements Callable<Boolean> {
    private  JSONObject param;
    private String key;
    private int index;
    private int type=0;
    static String isRedis= PropertiesUtil.getProperty("spring.redis.enable");
    @Override
    public Boolean call() throws Exception {
        if ("true".equals(isRedis)){
            switch (type){
                case 0:
                    /*Object 存储*/
                    RedisCache.set(index, key, param);
                    break;
                case 1:
                    /*list存储数据*/
                    RedisCache.insert(index,key, param);
                    break;
                case 2:
                    /*list存储数据*/
                    RedisCache.append(index,key, param);
                    break;
                default:
                    break;
            }
        }else {
            return false;
        }
       return true;
    }
    public RedisTaskCahe(String key, JSONObject value) {
        this.param=value;
        this.key=key;
        this.index=0;
    }
    public RedisTaskCahe(int indexDB,String key, JSONObject value) {
        this.param=value;
        this.key=key;
        this.index=indexDB;

    }
    public  RedisTaskCahe(String key,int type, JSONObject value) {
        this.param=value;
        this.key=key;
        this.index=0;
        this.type=type;
    }
    public  RedisTaskCahe(int indexDB,int type,String key, JSONObject value) {
        this.param=value;
        this.index=indexDB;
        this.key=key;
        this.type=type;
    }
}
